Skip to content

fix(http): preserve case-insensitive header precedence - #4417

Merged
Yuan325 merged 3 commits into
googleapis:mainfrom
feiiiiii5:codex/http-header-precedence
Nov 7, 2026
Merged

Yuan325 merged 3 commits into
googleapis:mainfrom
feiiiiii5:codex/http-header-precedence

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Description

Fixes #4416.

HTTP header names with different casing survived source/tool/parameter merges as separate map keys. They were canonicalized only when setting the request headers, so map iteration could let a lower-priority value replace an override. Canonicalize names as each layer is merged, preserving source < tool < provided parameter precedence and existing values/parameter behavior.

Validation on Go 1.27.3 (darwin/arm64):

  • The new deterministic header regression fails on the original code. The related package passes all 22 scenarios with go test -race -p=2 -count=1 -v -cover ./internal/tools/http, including a real HTTP source, tool invocation and local receiver. Package coverage increases from 35.2% to 69.4%.
  • Scoped go vet, golangci-lint 2.15.0 and its goimports formatter pass. go.mod/go.sum are unchanged.

Repository-wide checks, the authenticated Google fixture and full MCP endpoint tests were not run.

PR Checklist

  • Reviewed CONTRIBUTING.md.
  • Opened the issue before writing code.
  • Reviewed the entire diff.
  • Related tests and linter pass (scope above).
  • Coverage does not decrease for the affected package.
  • Existing header-precedence documentation remains accurate.
  • No breaking change marker is needed.

@feiiiiii5
feiiiiii5 requested a review from a team as a code owner November 4, 2026 20:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces case-insensitive header merging and overriding in the HTTP tool. It replaces direct map copying with a new mergeHeaders helper function that canonicalizes header keys using http.CanonicalHeaderKey. Additionally, it adds comprehensive unit tests to verify header precedence and case-insensitive overrides. No review comments were provided, so I have no feedback to address.

Remove import from source.

@Yuan325 Yuan325 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Yuan325 Yuan325 added the release candidate Use label to signal PR should be included in the next release. label Nov 6, 2026
@Yuan325

Yuan325 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

@Yuan325
Yuan325 enabled auto-merge (squash) November 6, 2026 23:29
@Yuan325
Yuan325 merged commit 8d54da0 into googleapis:main Nov 7, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release candidate Use label to signal PR should be included in the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP header precedence is lost when source and tool use different casing

2 participants